<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - 智慧后勤综合管理系统</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">

    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background: linear-gradient(135deg, #e0f7fa, #bbdefb, #90caf9);
            color: #333;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        header {
            background: rgba(255, 255, 255, 0.9);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            padding: 15px 0;
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .navbar {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .logo i {
            font-size: 28px;
            color: #2563eb;
        }

        .logo h1 {
            font-size: 24px;
            color: #2563eb;
            font-weight: 700;
        }

        .nav-links {
            display: flex;
            gap: 25px;
        }

        .nav-links a {
            text-decoration: none;
            color: #333;
            font-weight: 500;
            padding: 8px 12px;
            border-radius: 6px;
            transition: all 0.3s ease;
        }

        .nav-links a:hover, .nav-links a.active {
            background: #2563eb;
            color: white;
        }

        .user-actions {
            display: flex;
            gap: 15px;
            align-items: center;
        }

        .user-actions button {
            padding: 8px 16px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .login-btn {
            background: #2563eb;
            color: white;
        }

        .register-btn {
            background: #f0f7ff;
            color: #2563eb;
            border: 1px solid #2563eb !important;
        }

        .user-actions button:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }

        /* 登录页面样式 */
        .login-container {
            max-width: 500px;
            margin: 50px auto;
            padding: 40px;
            background: white;
            border-radius: 16px;
            box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
            position: relative;
        }

        .login-title {
            text-align: center;
            margin-bottom: 30px;
            color: #2563eb;
        }

        .form-group {
            margin-bottom: 25px;
            position: relative;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #555;
        }

        .form-group input {
            width: 100%;
            padding: 14px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            transition: border 0.3s ease;
        }

        .form-group input:focus {
            border-color: #2563eb;
            outline: none;
            box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
        }

        .password-toggle {
            position: absolute;
            right: 15px;
            top: 40px;
            cursor: pointer;
            color: #777;
        }

        .login-options {
            display: flex;
            justify-content: space-between;
            margin-bottom: 25px;
            font-size: 14px;
        }

        .remember-me {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .forgot-password {
            color: #2563eb;
            text-decoration: none;
        }

        .login-btn-container {
            text-align: center;
        }

        .login-submit {
            background: #2563eb;
            color: white;
            border: none;
            padding: 14px 30px;
            font-size: 16px;
            border-radius: 8px;
            cursor: pointer;
            width: 100%;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .login-submit:hover {
            background: #1d4ed8;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
        }

        .divider {
            text-align: center;
            margin: 25px 0;
            position: relative;
        }

        .divider::before {
            content: "";
            position: absolute;
            top: 50%;
            left: 0;
            right: 0;
            height: 1px;
            background: #eee;
            z-index: 1;
        }

        .divider span {
            background: white;
            padding: 0 15px;
            position: relative;
            z-index: 2;
            color: #777;
        }

        .other-login {
            display: flex;
            justify-content: center;
            gap: 20px;
            margin-top: 20px;
        }

        .other-login-btn {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 10px 20px;
            background: #f8fafc;
            border: 1px solid #e2e8f0;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .other-login-btn:hover {
            background: #eff6ff;
            transform: translateY(-2px);
        }

        footer {
            background: rgba(0, 0, 0, 0.7);
            color: white;
            text-align: center;
            padding: 20px;
            margin-top: auto;
        }

        .footer-content {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .copyright {
            font-size: 14px;
        }

        .footer-links {
            display: flex;
            gap: 20px;
        }

        .footer-links a {
            color: #ddd;
            text-decoration: none;
            transition: color 0.3s ease;
        }

        .footer-links a:hover {
            color: white;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .navbar {
                flex-direction: column;
                gap: 15px;
            }

            .nav-links {
                flex-wrap: wrap;
                justify-content: center;
            }

            .footer-content {
                flex-direction: column;
                gap: 15px;
            }
        }

        /* 状态消息样式 */
        #status-message {
            text-align: center;
            padding: 10px;
            border-radius: 8px;
            margin-bottom: 20px;
            display: none;
        }

        .success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }

        .loader {
            display: none;
            text-align: center;
            margin: 20px 0;
        }

        .loader .spinner {
            border: 4px solid rgba(0, 0, 0, 0.1);
            border-left-color: #2563eb;
            border-radius: 50%;
            width: 30px;
            height: 30px;
            animation: spin 1s linear infinite;
            margin: 0 auto;
        }

        @keyframes spin {
            to { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
<!-- 顶部导航栏 -->
<header>
    <div class="container">
        <nav class="navbar">
            <div class="logo">
                <i class="fas fa-cogs"></i>
                <h1>智慧后勤综合管理系统</h1>
            </div>
            <div class="nav-links">
                <a href="home.html">首页</a>
                <a href="mall.html">商城服务</a>
                <a href="search.html">搜索服务</a>
                <a href="profile.html">个人信息</a>
            </div>
            <div class="user-actions">
                <div id="login-buttons">
                    <button class="login-btn">登录</button>
                    <a href="register.html"><button class="register-btn">注册</button></a>
                </div>
            </div>
        </nav>
    </div>
</header>

<!-- 主内容区域 -->
<div class="container">
    <!-- 登录页面 -->
    <div class="login-container">
        <h2 class="login-title"><i class="fas fa-sign-in-alt"></i> 用户登录</h2>

        <div id="status-message"></div>
        <div class="loader">
            <div class="spinner"></div>
            <p>正在验证，请稍候...</p>
        </div>

        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" id="username" placeholder="请输入用户名">
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" id="password" placeholder="请输入密码">
            <i class="fas fa-eye password-toggle" id="togglePassword"></i>
        </div>
        <div class="login-options">
            <div class="remember-me">
                <input type="checkbox" id="remember">
                <label for="remember">记住我</label>
            </div>
            <a href="#" class="forgot-password">忘记密码?</a>
        </div>
        <div class="login-btn-container">
            <button class="login-submit" onclick="login()">登录</button>
        </div>

        <div class="divider">
            <span>或使用以下方式登录</span>
        </div>

        <div class="other-login">
            <button class="other-login-btn">
                <i class="fas fa-mobile-alt"></i>
                <span>手机登录</span>
            </button>
            <button class="other-login-btn">
                <i class="fas fa-sms"></i>
                <span>短信登录</span>
            </button>
        </div>

        <div class="demo-credentials">
            <p style="margin-top: 20px; text-align: center; color: #666; font-size: 14px;">
                <strong>演示账号：</strong>admin / admin123
            </p>
        </div>
    </div>
</div>



<script>
    fetch('http://localhost:8080/api/login', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({ username, password })
    })
        .then(res => res.json())
        .then(data => {
            if (data.success) {
                localStorage.setItem('currentUser', username);
                window.location.href = 'home.html';
            } else {
                showMessage('登录失败，请检查用户名或密码', false);
            }
        });

    // 密码可见性切换
    document.getElementById('togglePassword').addEventListener('click', function() {
        const passwordInput = document.getElementById('password');
        const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
        passwordInput.setAttribute('type', type);
        this.classList.toggle('fa-eye');
        this.classList.toggle('fa-eye-slash');
    });

    // 显示状态消息
    function showMessage(message, isSuccess) {
        const messageElement = document.getElementById('status-message');
        messageElement.textContent = message;
        messageElement.className = isSuccess ? 'success' : 'error';
        messageElement.style.display = 'block';

        // 5秒后隐藏消息
        setTimeout(() => {
            messageElement.style.display = 'none';
        }, 5000);
    }

    // 模拟登录功能
    function login() {
        const username = document.getElementById('username').value;
        const password = document.getElementById('password').value;
        const loader = document.querySelector('.loader');

        if(!username || !password) {
            showMessage('请输入用户名和密码！', false);
            return;
        }

        // 显示加载动画
        loader.style.display = 'block';

        // 模拟后端请求（实际项目中替换为真实API调用）
        setTimeout(() => {
            // 隐藏加载动画
            loader.style.display = 'none';

            // 模拟验证逻辑
            if(username === 'admin' && password === 'admin123') {
                showMessage('登录成功！正在跳转...', true);

                // 保存用户名到本地存储
                localStorage.setItem('currentUser', username);

                // 2秒后跳转到主页
                setTimeout(() => {
                    window.location.href = 'home.html';
                }, 2000);
            } else {
                showMessage('用户名或密码错误！', false);
            }
        }, 1500);
    }

    // 检查是否有记住的用户名
    window.onload = function() {
        const rememberedUser = localStorage.getItem('rememberedUser');
        if(rememberedUser) {
            document.getElementById('username').value = rememberedUser;
            document.getElementById('remember').checked = true;
        }
    };
</script>
</body>
</html>